﻿using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PlatformerCS
{
    public class FrameCounter
    {
        int frames;
        float fps;
        TimeSpan time;
        SpriteFont font;

        public FrameCounter()
        {
            time = TimeSpan.Zero;
            frames = 0;
            fps = 60;
        }

        public void LoadContent(ContentManager content)
        {
            font = content.Load<SpriteFont>("Fonts/Menu");
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            frames++;
            time += gameTime.ElapsedRealTime;

            if (time.Seconds > 1)
            {
                float total = time.Milliseconds + time.Seconds * 1000;
                fps = ((float)frames / total) * 1000;
                time = TimeSpan.Zero;
                frames = 0;
            }
            spriteBatch.DrawString(font, "Fps : " + (int)fps, new Vector2(GameBoard.WIDTH - 200, 0), Color.Black);
        }
    }
}
